<?php

namespace app\stuff\controller;


use app\stuff\model\Users as UsersModel;

use think\Controller;
use think\Session;
use think\Request;

class Main extends Controller
{
	public function __construct(Request $request)
	{
		parent::__construct($request);
		if (strstr($request->header('referer'), WEB_ROOT) == false) {
			$this->error('你好像迷路了呢，让我送你回去吧！', WEB_ROOT);
			exit();
		}
	}

	public function index(Request $request)
	{
		if (Session::has('name') && Session::has('CSUid')) {
			$name = $request->session('name');
			$CSUid = $request->session('CSUid');
			$users = new UsersModel();
			$check = $users->checkSession($name, $CSUid) ? true : false;
			if ($check) {
				$self = $users->self();
				$this->assign('self', $self);
				return $this->fetch('main/index');
			}
		}
		$this->redirect('index/index');
		return false;
	}
}
